package com.kaishengit.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.dao.ProductDao;

public class ProductServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");

		String bianhao = request.getParameter("bianhao");
		float price = Float.parseFloat(request.getParameter("price"));
		String productname = new String((request.getParameter("name")).getBytes("ISO8859-1"),"UTF-8");
		
		boolean isOr = Boolean.parseBoolean(request.getParameter("ison"));

		ProductDao dao = new ProductDao();
		dao.add(productname, price, isOr, bianhao);

		response.setContentType("text/xml;charset=UTF-8");
		PrintWriter out = response.getWriter();

		out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		out.print("<dat>");
		out.print("<recode1 date=\"" + bianhao + "\"></recode1>");
		out.print("<recode2 date=\"" + productname + "\"></recode2>");
		out.print("<recode3 date=\"" + price + "\"></recode3>");
		out.print("<recode4 date=\"" + isOr + "\"></recode4>");
		out.print("</dat>");

		out.flush();
		out.close();
	}
}
